package com.hmall.cart.listener;

import com.hmall.cart.service.ICartService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.index.qual.SameLen;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@Slf4j
@RequiredArgsConstructor
public class PayStatusListener {

    private final ICartService cartService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.clear.queue",durable = "true"),
            exchange = @Exchange(value = "trade.topic",type = ExchangeTypes.TOPIC,durable = "true"),
            key = "order.create"
    ))
    public void listenPaySuccess(Collection<Long> itemIds){
        //清除购物车
        cartService.removeByItemIds(itemIds);
        log.info("清除购物车成功 {}",itemIds);
    }
}
